package com.woniuxy.yogaapp.mapper;

import com.woniuxy.yogaapp.pojo.Consultation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: wanghao
 * @Date: 2019/8/11 23:11
 */
public interface ConsultationMapper {

    /**
     * 根据双方uid查询是否建立咨询关系
     * @param me
     * @param other
     * @return
     */
    @Select("select * from consultation where me = #{param1} and other = #{param2}")
    Consultation findConsultation(Integer me, Integer other);

    /**
     * 添加查询关系
     * @param meCon
     * @return
     */

    @Insert("insert into consultation(me, other, cname, cimage, roles) VALUES (#{me}, #{other},#{cname},#{cimage},#{roles})")
    int addConsultation(Consultation meCon);


    /**
     * 根据uid查询咨询对象
     * @param uid
     * @return
     */
    @Select("select * from consultation where me = #{uid}")
    List<Consultation> findConsultationByUid(Integer uid);

    /**
     * 取消咨询关系
     * @param me
     * @param other
     * @return
     */
    @Delete("delete from consultation where ( me = #{param1} and other = #{param2}) or (me = #{param2} and other = #{param1})")
    int deleteConsultation(Integer me, Integer other);
}
